Creating and Drawing Rectangles
You can create rectangle shapes and draw rectangles with QuickDraw GX the same way you create and draw points, lines, and curves. Typically, you first define a rectangle geometry, which is encapsulated in agxRectangle
structure:
struct gxRectangle { Fixed left; Fixed top; Fixed right; Fixed bottom; };Once you've defined a rectangle geometry, you can draw the corresponding rectangle without creating a rectangle shape by using the
- Note
- QuickDraw GX allows you to specify rectangle coordinates out of order--that is, you can specify any corner of the rectangle using the first two fields of the rectangle structure and the opposing corner using the third and fourth fields of the rectangle structure.
![]()
GXDrawRectangle
function or you can create a rectangle shape and draw it with theGXDrawShape
function, as shown in Listing 2-10.Listing 2-10 Creating a rectangle shape
void CreateRectangle(void) { gxShape aRectangleShape; static gxRectangle aRectangleGeometry = {ff(50), ff(50), ff(150), ff(100)}; aRectangleShape = GXNewRectangle(&aRectangleGeometry); GXDrawShape(aRectangleShape); GXDisposeShape(aRectangleShape); }This sample function uses theff
macro (which is an alias for theIntegerToFixed
macro) to convert integer constants to the fixed-point coordinate values needed to define a rectangle geometry. It then creates a rectangle shape using theGXNewRectangle
function (although it could use theGXNewShape
function or theGXNewShapeVector
function instead) and draws the rectangle using theGXDrawShape
function. The result is shown in Figure 2-23.
Notice that the rectangle is solid rather than framed. The
GXNewRectangle
function returns a new rectangle shape with the same shape fill property as the default rectangle shape, which is the even-odd shape fill.
To create a framed rectangle, you can use the
- Note
- Although initially QuickDraw GX sets the shape fill property of the default rectangle shape to be even-odd shape fill, you may change the default shape fill for rectangles by using the
GXGetDefaultShape
function to obtain a reference to the default rectangle and then using theGXSetShapeFill
function to change its shape fill. You can similarly change the default shape fill for any shape type.![]()
GXSetShapeFill
function to change the shape fill from even-odd to closed-frame, as shown in Listing 2-11.Listing 2-11 Creating a framed rectangle
void CreateFramedRectangle(void) { gxShape aRectangleShape; static gxRectangle aRectangleGeometry = {ff(150), ff(100), ff(50), ff(50)}; aRectangleShape = GXNewRectangle(&aRectangleGeometry); GXSetShapeFill(aRectangleShape, gxClosedFrameFill); GXDrawShape(aRectangleShape); }Figure 2-24 shows the result of Listing 2-11.Figure 2-24 A framed rectangle
In general, a rectangle can have any shape fill except open-frame shape fill. For more information about rectangle shapes, see "Rectangle Shapes" on page 2-20 and "The Rectangle Structure" on page 2-106.
For more information about the shape fill property, see "Shape Fill" beginning on page 2-12.
For information about the functions you can use to create and draw rectangles, see the description of the
GXNewRectangle
function on page 2-114 and theGXDrawRectangle
function on page 2-160.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help